class MyPage extends BasePopupEdit {
    constructor(dataId, pageStatus) {
        super(dataId, pageStatus);
        this._rows = 0;
    }
    OnPageLoad() {
        this.FetchForPage();
    }
    // 得到检索条件
    GetFilter() {
        let data = new Object();
        return $.toJSON(data);
    }
    //《按钮》显示全部
    FetchAll() {
        this.FetchForPage();
    }
    // 得到数据列表信息
    FetchForPage() {
        let _params = {};
        _params['LinesId'] = $("#LinesId").val();
        super.DoAjax(_params, "/trade/production_instruction/lines/size/fetchSuitSizeByParentLinesId.html", (data, _this) => {
            _this.BuildDataTable(data);
        });
    }
    BuildDataTable(result) {
        $("#tabData01 tbody").empty();

        if (result === null) {
            $('#loading').hide();
            return false;
        }
        this._rows = result.length;
        let content_01 = '';
        for (let i = 0; i < result.length; i++) {
            let id = result[i].linesId;
            content_01 += '<tr _mash_id="' + id + '" _mash_size_id="' + result[i].sizeId + '">';
            content_01 += '<td>' + result[i].styleNo + '</td>';
            content_01 += '<td style="border-right:none;" class="edited-cell">' + result[i].sizeName + '</td>';
            content_01 += '</tr>';

            $("#tabData01 tbody").append(content_01);
            content_01 = '';
        }

        setOneTableRowColor("tabData01");
        let id = "cell__field";
        let name = "_cell__field";
        $('#tabData01 tbody tr').find("td.edited-cell").click(function () {
            OnCellClickEvent($(this), id, name, 0);
        });
        this.AutoAdjustTableHeightForLines();    // 自适应高度设置
        $("#loading").hide();
    }
    GetLinesData() {
        let jsonUpdate = [];
        let itemResult = {};
        let suitSizeName = "";
        // 得到修改过数据
        $('#tabData01 tbody').find("tr").each(function () {
            let _linesId = $.trim($(this).attr("_mash_id"));
            //let _SizeId = $.trim($(this).attr("_mash_size_id"));
            if ($(this).find("td.dirty").length) {
                let item = {};
                let $row = $(this);

                item['linesId'] = _linesId;
                item['sizeName'] = $row.find("td").eq(1).text();
                item['createdBy'] = parseInt(parent.$("#UserId").val());
                item['updatedBy'] = parseInt(parent.$("#UserId").val());

                jsonUpdate.push(item);
            }
            suitSizeName += $(this).find("td").eq(1).text() + "-";
        });
        suitSizeName = suitSizeName.substring(0, suitSizeName.length - 1);      // 规范格式，去掉最后一个字符(-)
        itemResult['UpdateList'] = jsonUpdate;
        itemResult['SuitSizeName'] = suitSizeName.toUpperCase();
        return itemResult;
    }
    // 保存
    DoSave() {
        if (this.GetLinesData().UpdateList.length > 0) {
            super.DoAjax(this.GetLinesData(), "/trade/production_instruction/lines/size/update.html", (data, _this) => {
                parent.arrChoice.push(_this.GetLinesData().SuitSizeName);
                parent.choice_success = true;
                closePopupWnd();
            });
        }
    }
    AutoAdjustTableHeightForLines() {
        let h = $(window).height();
        let _top = $("#tabHeader01").offset().top + 25;
        let _rc = Math.floor((h - _top - 25) / 25);
        let _dh = _rc * 25;
        let _tah = this._rows * 25;
        _dh = (_tah >= _dh) ? _dh : _tah;

        $("#divContent").css({"max-height": _dh, height: _dh});
    }
}

//-----------------------------------------------------------------------------
// 页面初始化
//-----------------------------------------------------------------------------
function onPageReady() {
    $("#form_data").data("changed", false);   // 初始化form数据提交状态
    _Instance = new MyPage(0, 1);
    _Instance.OnPageLoad();
}

// 画面大小或者位置移动
function onPageResize() {
}
